Skip to content

Conversation

@lparry
Copy link

@lparry lparry commented Oct 14, 2025

Closes #4533 (partly at least)

Release Notes:

  • Added project_panel.sort_mode option to control explorer file sort (Directories first, mixed, macOS-like)

Summary

Adds three sorting modes for the project panel to give users more control over how files and directories are displayed:

  • directories_first (default): Current behaviour - directories grouped before files
  • mixed: Files and directories sorted together alphabetically
  • macos_like: Like mixed, but with case-insensitive sorting (Finder-style)

Motivation

Users coming from different editors and file managers have different expectations for file sorting. Some prefer directories grouped at the top (traditional), while others prefer the macOS Finder-style mixed sorting where "Apple1/", "apple2.tsx" and "Apple3/" appear alphabetically mixed together.

Changes

Core Implementation

  • Added ProjectPanelSortMode enum to settings with three variants
  • Implemented compare_rel_paths_mixed() for mixed file/directory sorting
  • Implemented compare_rel_paths_macos_like() for case-insensitive mixed sorting
  • Refactored sorting functions to accept a mode parameter while maintaining backward compatibility
  • Added sort_mode field to ProjectPanelSettings with directories_first as default

User Experience

  • Settings UI integration with dropdown selector in Panels section
  • Real-time panel updates when sort mode changes
  • Documentation added to visual-customization.md
  • All three modes use natural sorting for numbers (e.g., "file2" < "file10")

Screenshots

New sort options in settings:
image

Directories first Mixed macOS-like
image image image

Testing & Performance

  • Comprehensive test coverage including edge cases (basename collisions, nested paths, stability)
  • Benchmark suite to measure performance across all three modes (mixed is fastest, followed by macos-like, followed by the current implementation)
  • Fixed hard-coded path in benchmark to use CARGO_MANIFEST_DIR

Technical Details

Sorting Implementations:

  1. directories_first: Uses existing compare_rel_paths() - directories have inherent priority, then natural sort within each group

  2. mixed: New compare_rel_paths_mixed() - removes directory/file bias, compares by natural sort with deterministic full-path tie-breaking for entries like foo/ vs foo.rs

  3. macos_like: New compare_rel_paths_macos_like() - case-insensitive variant of mixed using natural_sort_case_insensitive() helper

Key Design Decisions:

  • Maintained backward compatibility with legacy sort_worktree_entries() functions
  • Used mode-aware wrappers (sort_worktree_entries_with_mode()) for new code
  • Settings observer triggers update_visible_entries() when sort mode changes
  • All sorting happens in-place for performance

Agent usage

Co-pilot/claude-code + claude sonnet 4.5 helped out a lot. I'm not from a rust background, but really wanted this solved

@cla-bot
Copy link

cla-bot bot commented Oct 14, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @lparry on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@lparry
Copy link
Author

lparry commented Oct 14, 2025

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 14, 2025
@cla-bot
Copy link

cla-bot bot commented Oct 14, 2025

The cla-bot has been summoned, and re-checked this pull request!

@lparry lparry force-pushed the lparry/more-file-sort-options branch 3 times, most recently from 5cc0a83 to 0f247cf Compare October 20, 2025 00:24
 ## Summary

Adds three sorting modes for the project panel to give users more
control over how files and directories are displayed:

- **`directories_first`** (default): Current behaviour - directories grouped before files
- **`interleaved`**: Files and directories sorted together alphabetically
- **`macos_like`**: Like interleaved, but with case-insensitive sorting (Finder-style)

 ## Motivation

Users coming from different editors and file managers have different
expectations for file sorting. Some prefer directories grouped at the
top (traditional), while others prefer the macOS Finder-style
interleaved sorting where "Apple1/", "apple2.tsx" and "Apple3/" appear
alphabetically mixed together.

 ## Changes

 ### Core Implementation

- Added `ProjectPanelSortMode` enum to settings with three variants
- Implemented `compare_rel_paths_interleaved()` for mixed file/directory sorting
- Implemented `compare_rel_paths_macos_like()` for case-insensitive interleaved sorting
- Refactored sorting functions to accept a mode parameter while maintaining backward compatibility
- Added `sort_mode` field to `ProjectPanelSettings` with `directories_first` as default

 ### User Experience

- Settings UI integration with dropdown selector in Panels section
- Real-time panel updates when sort mode changes
- Documentation added to visual-customization.md
- All three modes use natural sorting for numbers (e.g., "file2" < "file10")

 ### Testing & Performance

- Comprehensive test coverage including edge cases (basename collisions, nested paths, stability)
- Benchmark suite to measure performance across all three modes (interleaved is fastest, followed by macos-like, followed by the current implementation)
- Fixed hard-coded path in benchmark to use `CARGO_MANIFEST_DIR`

 ## Technical Details

**Sorting Implementations:**

1. **`directories_first`**: Uses existing `compare_rel_paths()` - directories have inherent priority, then natural sort within each group

2. **`interleaved`**: New `compare_rel_paths_interleaved()` - removes directory/file bias, compares by natural sort with deterministic full-path tie-breaking for entries like `foo/` vs `foo.rs`

3. **`macos_like`**: New `compare_rel_paths_macos_like()` - case-insensitive variant of interleaved using `natural_sort_case_insensitive()` helper

**Key Design Decisions:**

- Maintained backward compatibility with legacy `sort_worktree_entries()` functions
- Used mode-aware wrappers (`sort_worktree_entries_with_mode()`) for new code
- Settings observer triggers `update_visible_entries()` when sort mode changes
- All sorting happens in-place for performance
@lparry lparry force-pushed the lparry/more-file-sort-options branch from 0f247cf to d43b0be Compare October 20, 2025 00:29
@lparry
Copy link
Author

lparry commented Oct 20, 2025

I believe I have resolved the conflict & style linting problems now

@smitbarmase
Copy link
Member

@lparry I think there are still a bunch of errors when I try to compile it with cargo run. Can you give it a try and fix those errors?

in initializer of `workspace::ProjectPanelSettingsContent`
This is what vscode calls it and chews up less chars.
@lparry
Copy link
Author

lparry commented Oct 20, 2025

@smitbarmase That's embarrassing, sorry about that! I've sorted out those errors & the warning, renamed interleaved to mixed (matching the vscode order name), and pruned some pointless comments where claude didn't follow Claude.md very well.

Running a copy of the dev zed bundle for 148da0c built via ./script/bundle-mac -li now with no errors

@lparry lparry marked this pull request as draft October 22, 2025 04:55
@lparry
Copy link
Author

lparry commented Oct 22, 2025

I've found a bug in the behaviour where the children of an expanded directory are not anchored correctly to the expected parent directory. I'll see if I can work out where I've gone wrong

Noticed a bug after using this for a while in that the children of an
expanded directory could get separated from the parent directory node
by other similiarly named files.
@lparry lparry marked this pull request as ready for review October 22, 2025 07:31
@lparry
Copy link
Author

lparry commented Oct 22, 2025

@smitbarmase I've sorted out that bug now and added some more exhaustive tests that will hopefully cover more/most of the edge cases likely to come up.

Would love your opinion on if the default sort should be based on platform (so macos users automatically get the macos-like sort), or if it should remain as it is with the option of changing it to match the current OS? 🙏

@lparry lparry marked this pull request as draft October 24, 2025 07:34
@lparry
Copy link
Author

lparry commented Oct 24, 2025

Sorry to keep iterating on this after opening, but after screenshotting the various states I' realised that the directories first sort is supposed to be case insensitive, but another bug had tricked me into believing otherwise.

Realising that I think I can drop the case-sensitive mixed sort, and the near duplicate natural_sort_case_insensitive and simplify this a great deal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide an option to sort the files under folders in the sidebar

2 participants